﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <queue>
using namespace std;
//BITKY120 单词识别


int main() {
    string s;
    getline(cin,s);//输入一行英文
    vector<string> word;//存入单词
    for (auto& x : s)//把英文全部转小写
    {
        x = tolower(x);
    }

    size_t i = 0;
    while (i < s.size())//分割单词
    {
        string tmp;
        while (s[i] != ' ' && s[i] != '.')
        {
            
            tmp += s[i];
            i++;
        }
        i++;
        if (!(tmp.empty()))
        {
            word.push_back(tmp);//存单词
        }
    }
    map<string, int> dict;
    for (size_t i = 0; i < word.size(); i++)//记录单词出现次数
    {
        auto it = dict.find(word[i]);
        if ( it == dict.end())
        {
            dict.insert({ word[i], 1 });
        }
        else
        {
            it->second++;
        }
    }
    //打印单词
    for (const auto& x : dict)
    {
        cout << x.first << ':' << x.second << endl;
    }
    return 0;
}


//692. 前K个高频单词
//https://leetcode.cn/problems/top-k-frequent-words/
class Solution {
public:
    vector<string> topKFrequent(vector<string>& words, int k) {

        map<string, int> dict;//设置一个map存储单词出现的次数
        for (auto& x : words)
        {
            auto it = dict.find(x);
            if (it == dict.end())
            {
                dict.insert({ x, 1 });
            }
            else
            {
                it->second++;
            }
        }
        priority_queue<int> q;//用优先队列存储次数
        for (const auto& it : dict)
        {
            q.push(it.second);
        }

        vector<string> ret;
        for (size_t i = 0; i < k; i++)//取前k个
        {
            int tmp = q.top();//取出现最多单词的次数
            for (const auto& it : dict)//根据次数查找单词
            {
                if (it.second == tmp)
                {
                    ret.push_back(it.first);//找到单词后把单词存入返回的vector中
                    dict.erase(it.first);//删除当前单词防止重复查找
                    break;
                }
            }
            q.pop();
        }
        return ret;
    }
};